﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using XTeam.Document.Factory.ServiceInterface;
using Spring.Context;
using Spring.Context.Support;
using XTeam.Document.Entities;
using XTeam.Core.Helper;

namespace XTeam.Document.Controllers.Manage
{
    public class ArticleController : BasicController
    {
        private IArticleClassifyService _articleClassifyService;

        public ArticleController()
        {
            IApplicationContext _context = ContextRegistry.GetContext();
            _articleClassifyService = (IArticleClassifyService)_context.GetObject("ArticleClassifyService");
        }

        public ActionResult ClassifyList(int classId = 0)
        {
            var root = _articleClassifyService.Find(classId);
            root = root ?? _articleClassifyService.Root();
            return View(root);
        }
        [HttpGet]
        public ActionResult ClassifyPost(int classId = 0)
        {
            var node = _articleClassifyService.Find(classId);
            return View(node);
        }

        [HttpPost]
        public ActionResult ClassifyPost(ArticleClassifyEntity entity)
        {
            if (entity.ClassId <= 0)
            {
                _articleClassifyService.Append(entity);
            }
            else
            {

                _articleClassifyService.Update(entity);
            }

            return View(entity);
        }

        public ActionResult ClassifyPath(int classId = 0)
        {
            var node = _articleClassifyService.Find(classId);
            return View(node);
        }
    }
}
